﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text.RegularExpressions;

public static class ValidationExtensions
{
    public static bool IsEmail(this string value)
    {
        string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";
        //Regular expression object
        Regex check = new Regex(pattern,RegexOptions.IgnorePatternWhitespace);
        //boolean variable to return to calling method
        bool valid = false;
    
        //make sure an email address was provided
        if (string.IsNullOrEmpty(value))
        {
            valid = false;
        }
        else
        {
            //use IsMatch to validate the address
            valid = check.IsMatch(value);
        }
        //return the value to the calling method
        return valid;
    }
    
    public static bool IsFalse(this string value)
    {
        if(string.IsNullOrEmpty(value))
            return true;
        return !value.Equals("true",StringComparison.InvariantCultureIgnoreCase);
    }
}